/*
* 住院人次、门诊人次
* */

$(function () {

    let myChart = echarts.init(document.getElementById("rankChart1"));
   /* let option = {
        tooltip: {
            trigger: 'axis'
        },
        grid: {
            top: 20,
            bottom: 30,
        },
        legend: {
            data:['今年数据','去年数据'],
            textStyle:{
                color: '#b0c2f9'
            },
        },
        xAxis: [
            {
                type: 'category',
                boundaryGap: false,
                data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
                axisLabel: {
                    fontSize: 12,
                    color: "#b0c2f9"
                },
                axisPointer: {
                    type: 'shadow'
                },
            }
        ],
        yAxis: [
            {
                type: 'value',
                axisLabel: {
                    fontSize: 12,
                    color: "#b0c2f9"
                }
            }
        ],
        series: [
            {
                type: 'line',
                data: [ 820, 932, 901, 934, 1290, 1330, 1320, 820, 932, 901, 934, 1290 ],
                areaStyle: {},
                lineStyle: {
                    color: '#e6b600',
                    width: 2
                },
            },
            {
                type: 'line',
                data: [ 520, 632, 801, 534, 1220, 1230, 1120, 720, 832, 101, 434, 790 ],
                areaStyle: {},
                lineStyle: {
                    color: '#ed3f35',
                    width: 2
                },
            }
        ]
    };*/

    let option = {
        title: {  text: '' },
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data:['今年数据','去年数据'],
            textStyle:{
                color: '#b0c2f9'
            },
        },
        grid: {
            top: 20,
            bottom: 10,
            containLabel: true
        },
        color: ['#FF4949','#FFA74D','#FFEA51','#4BF0FF','#44AFF0','#4E82FF','#584BFF','#BE4DFF','#F845F1'],
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
            splitLine: {
                show: false
            },
            axisLine: {
                lineStyle: {
                    color: '#b0c2f9'
                }
            }
        },
        yAxis: {
            name: '',
            type: 'value',
            splitLine: { show: true },
            axisLine: {
                lineStyle: {
                    color: '#b0c2f9'
                }
            }
        },
        series: [
            {
                name:'今年数据',
                type:'line',
                data: [ 820, 932, 901, 934, 1290, 1330, 1320, 820, 932, 901, 934, 1290 ],
            },
            {
                name:'去年数据',
                type:'line',
                data: [ 520, 632, 801, 534, 1220, 1230, 1120, 720, 832, 101, 434, 790 ],
            }
        ]
    };

    if (option && typeof option === "object") {
        myChart.setOption(option, true);
    }

    $.ajax({
        url: "/hospital/total/hospital",
        dataType: "json"
    }).done(function(data) {
        const nowData = [];
        for(let i in data.result.now) {
            nowData.push(data.result.now[i].count);
        }
        const prevData = [];
        for(let i in data.result.prev) {
            prevData.push(data.result.prev[i].count);
        }
        myChart.setOption({
            series: [{
                name:'今年数据',
                type:'line',
                data: nowData,
                },{
                    name:'去年数据',
                    type:'line',
                    data: prevData,
            }]
        });
    }).fail(function(jqXHR) {
        console.log("Ajax Fail: ", jqXHR.status, jqXHR.statusText);
    });

    //浏览器窗口大小变化时，重置报表大小
    $(window).resize(function() {
        myChart.resize();
    });

});